var express = require('express')
var router = express.Router()
// 导入自己封装的数据库操作模块
const exec = require('../db')
//导入调试的标记
const { debug } = require('../config')

/* 仿写模板 */
router.get('/traffic', async (req, res) => {
  /*
    let { id } = req.params   // 获取:后面的参数 /:id
    const { pages, num } = req.query   // 获取?后面的参数 /messages?pages=1&num=5
    let { username, password } = req.body   // 获取请求体参数 {}
  */
  let sql = `select * from gg_traffic`

  try {
    let data = await exec(sql)
    res.send({
      code: 0,
      msg: '成功!',
      result: data,
    })
  } catch (err) {
    res.send({
      code: 1,
      msg: '失败!',
      result: debug ? err : '',
    })
  }
})
module.exports = router
